package com.imay.live.adapter;

import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.imay.base.util.StringUtil;
import com.imay.live.R;
import com.imay.live.model.RoomInfoModel;
import com.imay.live.utils.GlideUtil;

import java.util.List;

/**
 * Created by liangzhenxiong on 2017/4/6 0006.
 */

public class GameLiveAdapter extends BaseQuickAdapter<RoomInfoModel, BaseViewHolder> {

    private boolean isNormalLive;
    public GameLiveAdapter(List<RoomInfoModel> data,boolean isNormalLive) {
        super(R.layout.item_discovery_live, data);
        this.isNormalLive = isNormalLive;
    }
    public GameLiveAdapter(List<RoomInfoModel> data) {
        super(R.layout.item_discovery_live, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, RoomInfoModel item) {
        int leftMargin;
        int rightMargin;
        int postion = helper.getAdapterPosition() - getHeaderLayoutCount();
        if (postion % 2 == 0) {
            leftMargin = 6;
            rightMargin = 3;
        } else {
            leftMargin = 3;
            rightMargin = 6;
        }
        View view = helper.getView(R.id.discover_live_rl_square);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(leftMargin, 0, rightMargin, 0);
        view.setLayoutParams(layoutParams);
        helper.addOnClickListener(R.id.discover_live_rl_square);
//        helper.addOnClickListener(R.id.discover_live_tv_nick);
        ImageView discover_live_iv_live = helper.getView(R.id.discover_live_iv_live);
        discover_live_iv_live.setImageResource(isNormalLive?R.mipmap.live:R.mipmap.ico_00game);
//        UserModel userModel = item.getUser();
//        if (userModel != null) {
//            TextView discover_live_tv_nick = helper.getView(R.id.discover_live_tv_nick);
//            discover_live_tv_nick.setText(userModel.getNick());
//            Drawable drawable = null;
//            int resId = LevelHelper.getVIPIcon(userModel.getVip());
//            if (resId != 0) {
//                drawable = mContext.getResources().getDrawable(LevelHelper.getVIPIcon(userModel.getVip()));
//                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
//            }
//            discover_live_tv_nick.setCompoundDrawables(null, null, drawable, null);
//
//        }
        String name = null;
        if (TextUtils.isEmpty(item.getTitle())) {
            if (item.getUser() != null) {
                name = item.getUser().getNick();
            }
        } else {
            name = item.getTitle();
        }
        helper.setText(R.id.discover_live_tv_title, name);
        helper.setText(R.id.discover_live_tv_location, TextUtils.isEmpty(item.getCity()) ? helper.getConvertView().getResources().getString(R.string.str_dynamics_address) : item.getCity());
        helper.setText(R.id.discover_live_tv_number, String.valueOf(item.getCountUser()));
        String coverUrl = StringUtil.isEmpty(item.getImgFace()) && item.getUser() != null ? item.getUser().getImgHead() : item.getImgFace();
        GlideUtil.loadRectangleImage((ImageView) helper.getView(R.id.discover_live_iv_cover),coverUrl, R.dimen.size_4dp, R.drawable.shape_placeholder_2);
    }
}
